#include<iostream>
#include<cstring>
#include<unordered_map>
#include<queue>
using namespace std;
typedef long long LL;
unordered_map<LL, int>mp;
LL x;
queue<LL>q;
int n;
bool check(LL x)
{
	int cnt = 0;
	while (x) {
		cnt++;
		x /= 10;
	}
	return cnt == n;
}
int bfs(LL x)
{
	mp[x] = 0;
	q.push(x);
	while (q.size()) {
		LL t = q.front();
		q.pop();
		LL u = t;
		while (u) {
			int d = u % 10;
			u /= 10;
			LL v = d * t;
			if (!mp.count(v)) {
				mp[v] = mp[t] + 1;
				if (check(v))return mp[v];
				q.push(v);
			}
		}
	}
	return -1;
}
int main()
{
	cin >> n >> x;
	if (n != 1 && x == 1) {
		cout << -1 << endl;
	}
	else cout << bfs(x) << endl;
	return 0;
}